package com.example.lockfulldemo.listener;

import cn.hutool.json.JSONUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

@Slf4j
@Component
@RequiredArgsConstructor
public class TransactionalMessageListener {



    /**
     *
     * @param num -
     */
    @TransactionalEventListener
    public void sendOrderMessage(String num) {
        log.info("监听到的消息体:{}", JSONUtil.toJsonStr(num));


    }


    /**
     *
     * @param num -
     */
    @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT,fallbackExecution = true)
    public void sendOrderMessage1(Integer num) {
        log.info("监听到的消息体:{}", JSONUtil.toJsonStr(num));


    }

//    @Override
//    public void afterPropertiesSet() {
//        log.info("RabbitTemplate ConfirmCallback 配置完成");
//
////        RabbitTemplate rabbitTemplate = this.rabbitCustomService.getRabbitTemplate(OmsMQConstant.OMS_EXCHANGE);
////        rabbitTemplate.setConfirmCallback((correlationData, ack, cause) -> {
////            if (ack) {
////                log.info("消息 ack 成功 [{}]", correlationData);
////                this.messageCacheService.updateStatus(correlationData, cause, MessageCacheStatusEnum.ONE);
////            } else {
////                log.error("消息 ack 失败 [{}, {}]", correlationData, cause);
////                this.messageCacheService.updateStatus(correlationData, cause);
////            }
////        });
//
//    }

}
